<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Insert title here</title>
	</head>

	<body>
		<jsp:include page="/WEB-INF/jsp/lib.jsp" />
		<script type="text/javascript" src="js/locale/easyui-lang-zh_CN.js"></script>
		<table>
			<tr>姓名：</tr>
			<tr>
				<input type="text" id="staffName" />
			</tr>
			&nbsp;
			<tr>性别：</tr>
			<tr>
				<select id="selsex">
					<option value="">全部</option>
					<option value="1">男</option>
					<option value="0">女</option>
				</select>
			</tr>
			&nbsp;
			<tr>职位：</tr>
			<tr>
				<select id="selid">
					<option value="">全部</option>
				</select>
			</tr></br>
			<tr>生日上限：</tr>
			<tr>
				<input id="sbirthday" type="text" class="easyui-datebox" ></input>
			</tr>
			&nbsp
			<tr>生日下限：</tr>
			<tr>
				<input id="ebirthday" type="text" class="easyui-datebox" ></input>
			</tr>
			&nbsp
			<tr>入职上限：</tr>
			<tr>
				<input id="senty" type="text" class="easyui-datebox" ></input>
			</tr>
			&nbsp
			<tr>入职下限：</tr>
			<tr>
				<input id="enty" type="text" class="easyui-datebox" ></input>
			</tr>
		</table>
		<button id="but">搜索</button>
		<table id="ta"></table>
	</body>
	<script type="text/x-javascript">
		//页面加载完成之后
		$(function() {
			//点击按钮查询
			$("#but").click(function(){
				//获取输入后的数据
				var staffName = $("#staffName").val()
				var selsex = $("#selsex").val()
		var position_id = $("#selid").val()
				var sbirthday = $("#sbirthday").datebox("getValue")
				var ebirthday = $("#ebirthday").datebox("getValue")
				var senty = $("#senty").datebox("getValue")
				var enty = $("#enty").datebox("getValue")
				//带着参数刷新表格
				$('#ta').datagrid({
					queryParams:{
						name:staffName,
						sex:selsex,
					positionId:position_id,
						startBirthdayTime:sbirthday,
						endBirthdayTime:ebirthday,
						startEntryTime:senty,
						endEntryTime:enty
					}
				})
			})
			
			//发送ajax获取option数据
			$.ajax({
				url:"${pageContext.request.contextPath}/posd/select.do",
				data:{page:1,rows:900},
				//回调函数
				success:function(data){
					//将部门数据迭代
					$(data.rows).each(function(){
						var option = '<option value='+this.id+'>'+this.positionName+'</option>'
							$("#selid").append(option)
					})
				}
			});

			//初始化表格
			$("#ta").datagrid({
				url: "${pageContext.request.contextPath}/staff/list.do",
				//birthday":1523438994000,"positionName":"人力资源主管","entry":1510055935000,"update_time":784382301000,"create_time":784382301000,"positionId":1,"sex":1,"name":"任翔","id":1
				columns: [
					[{
							field: 'id',
							title: '员工id',
							width: 100
						},
						{
							field: 'name',
							title: '姓名',
							width: 100
						},
						{
							field: 'sex',
							title: '性别',
							width: 100,
							formatter: function(value){
								if(value == 1 ){
									return '男';
								}else if(value == 0){
									return '女';
								}
							}
						},
						{
							field: 'birthday',
							title: '生日',
							width: 100,
							formatter : function(value) {
								if (value) {
									var date = new Date(value);
									//获取区年
									var year = date.getFullYear();
									var month = date.getMonth() + 1;
									var date1 = date.getDate();
									var d = year + "/" + month + "/"
											+ date1 ;
									return d;
								}
							}
						},
						{
							field: 'entry',
							title: '入职时间',
							width: 100,
							formatter : function(value) {
								if (value) {
									var date = new Date(value);
									//获取区年
									var year = date.getFullYear();
									var month = date.getMonth() + 1;
									var date1 = date.getDate();
									var d = year + "/" + month + "/"
											+ date1 ;
									return d;
								}
							}
						},
						{
							field: 'positionName',
							title: '职位',
							width: 100
						},
						{
							field: 'update_time',
							title: '修改时间',
							width: 100,
							formatter : function(value) {
								if (value) {
									var date = new Date(value);
									//获取区年
									var year = date.getFullYear();
									var month = date.getMonth() + 1;
									var date1 = date.getDate();
									var hours = date.getHours();
									var min = date.getMinutes();
									var d = year + "/" + month + "/"
											+ date1 + " " + hours + ":"
											+ min ;
									return d;
								}
							}
							
						},
						{
							field: 'create_time',
							title: '创建时间',
							width: 100,
							formatter : function(value) {
								if (value) {
									var date = new Date(value);
									//获取区年
									var year = date.getFullYear();
									var month = date.getMonth() + 1;
									var date1 = date.getDate();
									var hours = date.getHours();
									var min = date.getMinutes();
									var d = year + "/" + month + "/"
											+ date1 + " " + hours + ":"
											+ min ;
									return d;
								}
							}
						},

					]
				],
					//开启分页工具栏
					pagination: true,
					//以适应网格的宽度
					fitColumns: true,
					//在设置分页属性的时候 初始化页面大小选择列表。
					pageList: [5, 10, 15],
					//在设置分页属性的时候初始化页面大小。
					pageSize: 5,
					//在设置分页属性的时候初始化页码。
					pageNumber: 1
			})

		})
	</script>

</html>